﻿Imports Microsoft.Office.Interop.Access

Public Enum SVNAccessObjectType

    acform = AcObjectType.acForm
    acreport = AcObjectType.acReport
    acMacro = AcObjectType.acMacro
    acQuery = AcObjectType.acQuery
    acModule = AcObjectType.acModule
    acTable = AcObjectType.acTable
    acVBAReference = 100

End Enum
Public Enum enumSvnOperation
    DELETE
    ADD
    UPDATE
End Enum
Public Interface IExportedAccessObject

    Property Name As String
    Property type As SVNAccessObjectType
    Property svnOperation As enumSvnOperation

End Interface

''' <summary>
''' Exported Object information
''' </summary>
''' <remarks></remarks>
<Serializable()>
Public Class ExportedAccessObject
    Implements IExportedAccessObject
    Implements IComparable(Of ExportedAccessObject)

    Public Property Name As String Implements IExportedAccessObject.Name
    Public Property type As SVNAccessObjectType Implements IExportedAccessObject.type

    Public Sub New(ByVal _name As String, ByVal _type As SVNAccessObjectType, ByVal operation As enumSvnOperation)
        Me.New(_name, _type)
        Me.svnOperation = operation
    End Sub
    ''' <summary>
    ''' Creates a new object from a list of files as retrieved by svn diff revsion --summarize
    ''' </summary>
    ''' <param name="objFilePath"></param>
    ''' <param name="operation"></param>
    ''' <remarks></remarks>
    Public Sub New(ByVal objFilePath As String, ByVal operation As String)

        Me.Name = getObjectNameFromSVNPath(objFilePath)

        If Right$(UCase$(objFilePath), 4) = ".ACR" Then
            'DoCmd.Rename rname & "_imported", acReport, rname
            Me.type = SVNAccessObjectType.acreport

        ElseIf Right$(UCase$(objFilePath), 4) = ".ACF" Then
            Me.type = SVNAccessObjectType.acform

        ElseIf Right$(UCase$(objFilePath), 4) = ".ACM" Then
            Me.type = SVNAccessObjectType.acModule

        ElseIf Right$(UCase$(objFilePath), 4) = ".ACS" Then
            Me.type = SVNAccessObjectType.acMacro

        Else
            Throw New ApplicationException("Unhandled type:" & objFilePath)
        End If

        If operation = "D" Then
            Me.svnOperation = enumSvnOperation.DELETE
        ElseIf operation = "M" Then
            Me.svnOperation = enumSvnOperation.UPDATE
        Else
            Me.svnOperation = enumSvnOperation.ADD
        End If

    End Sub

    Public Shared Function getObjectNameFromSVNPath(ByVal objSvnPath As String) As String

        Dim idx As Integer

        idx = InStr(objSvnPath, "\")
        Dim ret As String = Left(objSvnPath, Len(objSvnPath) - 4)
        ret = Mid$(ret, idx + 1)
        Return ret

    End Function

    Public Sub New(ByVal _name As String, ByVal _type As SVNAccessObjectType)

        Me.Name = _name
        Me.type = _type

    End Sub

    Public Function CompareTo(ByVal other As ExportedAccessObject) As Integer _
            Implements System.IComparable(Of ExportedAccessObject).CompareTo

        If other Is Nothing Then
            Return -1
        End If

        Return Me.Name.CompareTo(other.Name)

    End Function

    Public Overrides Function Equals(ByVal other As Object) As Boolean

        If other Is Nothing Then
            Return False
        End If

        Return Me.Name.Equals(CType(other, ExportedAccessObject).Name)

    End Function

    Public Property svnOperation As enumSvnOperation = enumSvnOperation.ADD Implements _
            IExportedAccessObject.svnOperation

       
End Class